package hotel.player;

import hotel.util.ObservableModel;


public class Player extends ObservableModel implements IModifiablePlayer {
	
	// ATTRIBUTS
	
	private final String name;
	private long balance;
	
	// CONSTRUCTEURS
	
	public Player(String name) {
		this.name = name;
	}
	
	// REQUETES

	@Override
	public String getName() {
		return name;
	}

	@Override
	public long getBalance() {
		return balance;
	}
	
	// COMMANDES

	@Override
	public void setBalance(long qty) {
		if (qty < 0) {
			throw new IllegalArgumentException();
		}
		long old = balance;
		balance = qty;
		listeners.firePropertyChange("balance", old, balance);
	}

	@Override
	public void addMoney(long qty) {
		if (qty < 0) {
			throw new IllegalArgumentException();
		}
		long old = balance;
		balance += qty;
		listeners.firePropertyChange("balance", old, balance);
	}

	@Override
	public void subMoney(long qty) {
		if (qty < 0) {
			throw new IllegalArgumentException();
		}
		long old = balance;
		balance -= qty;
		listeners.firePropertyChange("balance", old, balance);
	}

}
